<?php
$__chat_conn;
function createDb(){
    global $__chat_conn;
    if($__chat_conn) return $__chat_conn;
    return $__chat_conn = new mysqli("localhost","root","","mychat");
}
function query($sql){
    $conn = createDb();
    $rs = $conn->query($sql);
    return $rs;
}
function query_rows($sql){
    $conn = createDb();
    $rs = $conn->query($sql);
    if($conn->error) die($conn->error);
    $rows = [];
    while($row = $rs->fetch_assoc()){
        $rows[] = $row;
    }
    $rs->close();
    return $rows;
}
function query_single($sql){
    $conn = createDb();
    $rs = $conn->query($sql);
    if($conn->error) die($conn->error);
    
    $row = $rs->fetch_assoc();
    $rs->close();
    return $row;
}
function nowstr(){
    return date_format(new DateTime(),"Y-m-d H:i:s");
}